
<div class="x_panel">
  <div class="x_content" style="display: block;">
    <!--表格主体内容-->
    <div class="row-fluid">
      <form action="/goods/yanxuan.html" method="get">
        <label class="control-label">SPUID</label>
        <input type="text" class="form-control-new" name="form[spuid]" value="{if isset($query.spuid)}{$query.spuid}{/if}">
        <label class="control-label">商品名称</label>
        <input type="text" class="form-control-new" name="form[goods_name]" value="{if isset($query.goods_name)}{$query.goods_name}{/if}">
        <label class="control-label">状态</label>
        <select  class="form-control-new" name="form[status]" >
          <option {if !isset($query.status) || $query.status==-1}selected="selected"{/if} value="-1">全部</option>
          <option {if isset($query.status) && $query.status==1}selected="selected"{/if} value="1">上架中</option>
          <option {if isset($query.status) && $query.status==0}selected="selected"{/if} value="0">已下架</option>
          <option {if isset($query.status) && $query.status==2}selected="selected"{/if} value="2">未上架</option>
        </select>

        <label class="control-label">一级类目</label>
        <select id="first_category" class="form-control-new" name="form[first_category]" >
          <option {if !isset($query.first_category) || $query.first_category=="全部"}selected="selected"{/if} value="0">全部</option>
          {foreach $local_search_first_category AS $value1}
          <option {if isset($query.first_category) && $query.first_category==$value1.category_id}selected="selected"{/if} value="{$value1.category_id}">{$value1.category_name}</option>
          {/foreach}
        </select>
        <label class="control-label">二级类目</label>
        <select id="second_category" class="form-control-new" name="form[second_category]" >
          <option {if !isset($query.second_category) || $query.second_category=="全部"}selected="selected"{/if} value="0">全部</option>
          {if isset($goods.second_category) && $goods.second_category}
          {foreach $goods.second_category AS $value2}
          <option {if isset($query.second_category) && $query.second_category==$value2.category_id}selected="selected"{/if} value="{$value2.category_id}">{$value2.category_name}</option>
          {/foreach}
          {/if}
        </select>
        <button type="submit" class="btn btn-primary" >查询</button>
      </form>

        <input id="spuid" name="spuid" type="hidden" value="">
        <button id="batch_on" type="submit" class="btn btn-primary" >批量上架</button>

    </div>
    <br>
    <div class="cont">
      <table class="table table-bordered table-striped">
        <thead>
        <tr>
          <th width="100px"></th>
          <th width="100px">SPU ID</th>
          <th>商品名称</th>
          <th>图片</th>
          <th>商品描述</th>
          <th>类目</th>
          <!--<th>严选价格</th>
          <th>合约价格</th>
          <th>销售价格</th>-->
          <th>状态</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $goods.lists as $goodsitem}
        <tr>
          <td><input type="checkbox" name="form[goods_id]" value="{$goodsitem.yx_goods_id}"/></td>
          <td>{$goodsitem.yx_goods_id}</td>
          <td>{$goodsitem.goods_name}</td>
          <td><img src="{$goodsitem.goods_pic}" width="50px" height="50px" /> </td>
          <td width="200px">{$goodsitem.simple_desc}</td>
          <td>
            {$goodsitem.first_category_name}<br/>{$goodsitem.second_category_name}
          </td>
          <!--<td>{$goodsitem.yanxuan_price}</td>
          <td>{$goodsitem.channel_price}</td>
          <td>{$goodsitem.goods_price}</td>-->
          <td>{if $goodsitem.status==2}未上架{else if $goodsitem.status==0}已下架{else}上架中{/if}</td>
          <td>
            <div class="x_content">
              <a class="btn btn-primary btn-xs" href="{eval U(['goods/sku-detail','id'=>$goodsitem.yx_goods_id])}"> 查看SKU</a>
              <a class="btn btn-primary btn-xs" href="{eval U(['goods/on-sale','id'=>$goodsitem.yx_goods_id])}"> 上架</a>

            </div>
          </td>
        </tr>
        {/foreach}
        </tbody>
      </table>
      <!--分页-->
      {Yii::$app->view->render('/com/pager.php',['pager'=>$goods.pager])}

    </div>




  </div>
</div>

<script>
    /*$('#first_category').change(function (e) {
        var category_name = this.value;
        var url = "{['goods/get-second-category']|U}";
        $.post(url, 'category_name='+category_name, function (data) {
            $('#second_category').html('');
            $('#second_category').append('<option selected="selected" value="全部">全部</option>');
            for(var i=0; i<data.length; i++){
                $('#second_category').append("<option value= '"+data[i]+"'>"+data[i]+"</option>");
            }
        },'json');
    })*/
    $('#first_category').change(function (e) {
        var category_id = this.value;
        var url = "{['goods/get-second-category-by-id']|U}";
        $.post(url, 'category_id='+category_id, function (data) {
            $('#second_category').html('');
            $('#second_category').append('<option selected="selected" value="0">全部</option>');
            for(var i=0; i<data.length; i++){
                $('#second_category').append("<option value= '"+data[i].category_id+"'>"+data[i].category_name+"</option>");
            }
        },'json');
    })

  $("#batch_on").click(function (e){
      /*var goods_ids = $("input[type='checkbox']").val();
      console.log(goods_ids);*/
      var arr = new Array();
      $('input:checkbox').each(function(i) {
          if($(this).is(":checked")) {
              arr[i] =$(this).val();
          }
      });
      var vals = arr.join(",");

      if(vals){
          /*var url = "{['goods/on-sale']|U}";
          $.post(url, 'yx_goods_ids='+vals, function (data) {
              alert("上架成功")
          },'json');*/
          window.location.href = "batch-on.html?yx_goods_ids="+vals;
      }
  })

</script>
